﻿
@{
    Layout = "";
}
<style>
    .my-drop-zone {
        border: dotted 3px lightgray;
    }

    .nv-file-over {
        border: dotted 3px red;
    }

    /* Default class applied to drop zones on over */

    .another-file-over-class {
        border: dotted 3px green;
    }

    html, body {
        height: 100%;
    }

    canvas {
        -moz-box-shadow: 3px 3px 3px 0 #e3e3e3;
        -webkit-box-shadow: 3px 3px 3px 0 #e3e3e3;
        background-color: #f3f3f3;
        border: 1px solid #c3c3c3;
        box-shadow: 3px 3px 3px 0 #e3e3e3;
        height: 100px;
        margin: 6px 0 0 6px;
    }

    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 55% !important;
    }
</style>
<div ng-controller="SpecialTopicEditController">
    <div class="container-fluid" ng-show="!selectProduct">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START panel-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading }">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>{{ActivityRule.ID == 0 || ActivityRule.ID == null ? '添加规则' : '修改规则'}}</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">请选择规则类型</label>
                                    <div class="col-sm-4">
                                        <select class="form-control" ng-model="ActivityRule.RuleType" >
                                            <option value="0">一分钱活动</option>
                                            <option value="1">降拼活动</option>
                                        </select>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">活动规则</label>
                                    <div class="col-sm-4">
                                        <input type="text" required="" ng-model="ActivityRule.RuleContent" class="form-control" name="RuleContent" maxlength="50" />
                                        <span ng-show="validateInput('RuleContent', 'required')" class="text-danger">请输入活动规则</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                        <div class="panel-footer text-right">
                            <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                    <!-- END panel-->
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    App.controller('SpecialTopicEditController', [
        "$scope", "$state", "$http", "$stateParams", "Notify", "ngDialog", 'ngTableParams', '$rootScope', '$filter',
        function ($scope, $state, $http, $stateParams, Notify, ngDialog, ngTableParams,  $rootScope, $filter) {
            'use strict';

            $scope.submitted = false;
            $scope.ActivityRule = {};
            $scope.ActivityRule.RuleType = 0;
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };

          

            //数据初始化
            if ($stateParams.id && $stateParams.id > 0) {
                $scope.isLoading = true;
                $http.post("/Activity/ActivityRuleEdit", { id: $stateParams.id }).then(function (response) {
                    debugger;
                    if (response.data.Result && response.data.Result != "") {
                        $scope.ActivityRule = response.data.Result;
                    }
                    $scope.isLoading = false;
                });
            }

            // 提交
            $scope.submitForm = function () {
                debugger;
                $scope.isLoading = true;
                $scope.submitted = true;
                if ($scope.formValidate.$valid) {
                    $http.post("/Activity/SaveActivityRule", $scope.ActivityRule).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success', timeout: 1000 });
                            $state.go("app.activityrulelist");
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
                        }
                        $scope.isLoading = false;
                    });
                } else {
                    $scope.isLoading = false;
                    return false;
                }
            };

            //返回列表
            $scope.cancel = function () {
                $state.go("app.activityrulelist");
            };

           

        }
    ]);
</script>